package com.xiaoyu.base.view.list;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import com.xiaoyu.base.R;

import in.srain.cube.util.CLog;
import in.srain.cube.views.loadmore.LoadMoreContainer;
import in.srain.cube.views.loadmore.LoadMoreUIHandler;

public class LoadMoreFooterView extends RelativeLayout implements LoadMoreUIHandler {

    private static final String TAG = "LoadMoreFooterView";

    private ProgressBar mProgressBar;

    public LoadMoreFooterView(Context context) {
        this(context, null);
    }

    public LoadMoreFooterView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LoadMoreFooterView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setupViews();
    }

    private void setupViews() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_load_more_footer_view, this);
        mProgressBar = findViewById(R.id.views_load_more_footer_view_progress_bar);
    }

    @Override
    public void onLoading(LoadMoreContainer container) {
        CLog.d(TAG, "onLoading: %s", this);
        setVisibility(VISIBLE);
        mProgressBar.setVisibility(VISIBLE);
    }

    @Override
    public void onLoadFinish(LoadMoreContainer container, boolean empty, boolean hasMore) {
        CLog.d(TAG, "onLoadFinish: empty?: %s, hasMore?: %s, %s", empty, hasMore, this);
        mProgressBar.setVisibility(GONE);
        if (hasMore) {
            setVisibility(VISIBLE);
        } else {
            setVisibility(GONE);
        }
    }

    @Override
    public void onWaitToLoadMore(LoadMoreContainer container) {
        CLog.d(TAG, "onWaitToLoadMore: %s", this);
        mProgressBar.setVisibility(GONE);
    }

    @Override
    public void onLoadError(LoadMoreContainer container, int errorCode, String errorMessage) {
    }
}
